package com.demo.designmode.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: jxm
 * @Description: 微信公众号是具体主题（具体被观察者）
 * @Date: 2023-12-12 10:38
 * @Version: 1.0
 */
public class SubscriptionSubject implements Subject{

    //储存订阅公众号的微信用户
    private List<Observer> weixinUserList = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weixinUserList.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weixinUserList.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weixinUserList) {
            observer.update(message);
        }
    }
}
